Ext
		.onReady(function() {
			var vstore = new Ext.data.JsonStore({
				url : "getemployees.do",
				// data : data1,
				autoLoad : true,
				fields : [ "area", "birthday", "code", "id", "idcard", "name",
						"pname", "pcode" ]
			// autoDestroy : true,
			// reader configs
			// root : 'images',
			// idProperty : 'name',
			});

			var grid = new Ext.grid.GridPanel(
					{
						store : vstore,
						layout : 'fit',
						border : true,
						tbar : [
								{
									text : "添加",
									handler : function() {
										var win = new Ext.Window(
												{
													width : 313,
													border : 0,
													height : 330,
													modal : true,
													resizable : false,
													items : {
														labelAlign : "right",
														title : '用户基本信息',
														border : 0,
														height : 300,
														width : 300,
														xtype : "form",
														closable : false,
														// fileUpload:true,
														buttons : [
																{
																	text : "提交",
																	handler : function() {
																		// 要对表单里面的东西进行操作，需要用到BasicForm类中的方法
																		// 要得到一个BasicForm的实例，需要调用FormPanel对象上面的getForm方法，fp.form可得到BasicForm对象
																		/*
																		 * this
																		 * .getForm()
																		 * .submit( {
																		 * url :
																		 * "inseremployees.do",
																		 * success :
																		 * function() {
																		 * Ext.Msg
																		 * .alert(
																		 * "提交",
																		 * "数据保存成功！"); }
																		 * });
																		 */

																		win
																				.getComponent(
																						0)
																				.getForm()
																				.submit(
																						{
																							url : 'inseremployees.do',
																							success : function() {
																								alert("添加成功！");
																								win
																										.hide();
																								vstore
																										.reload();
																							}
																						});

																	}
																},
																{
																	text : "重置",
																	handler : function() {
																		Ext.Msg
																				.alert(
																						"提示",
																						fpanel.form
																								.findField(
																										"name")
																								.getValue());
																		fpanel.form
																				.reset();
																	}
																},
																{
																	text : "设值",
																	handler : function() {
																		alert(win
																				.getComponent(
																						0)
																				.getForm()
																				.getEl(
																						"code")
																				.getValue());
																	}
																} ],
														items : [

																{
																	xtype : "textfield",
																	fieldLabel : "员工号",
																	name : "code",
																	id : "code"
																},
																{
																	xtype : "textfield",
																	fieldLabel : "员工姓名",
																	name : "name"
																},
																{
																	xtype : "datefield",
																	fieldLabel : "生日",
																	name : "birthday",
																	format : 'Y-m-d'
																},
																{
																	xtype : "textfield",
																	fieldLabel : "区域",
																	name : "area"
																},
																{
																	xtype : "textfield",
																	fieldLabel : "证件号码",
																	name : "idcard"
																},
																{
																	xtype : "textfield",
																	fieldLabel : "上级员工编号",
																	name : "pcode",
																	id : "pcode"
																} ]
													}
												});
										win.show();
									}
								},
								'-',
								{
									text : "修改",
									handler : function() {
										var win = new Ext.Window(
												{
													width : 313,
													border : 0,
													height : 330,
													modal : true,
													resizable : false,
													items : {
														labelAlign : "right",
														title : '用户基本信息',
														border : 0,
														height : 300,
														width : 300,
														xtype : "form",
														closable : false,
														// fileUpload:true,
														buttons : [
																{
																	text : "提交",
																	handler : function() {

																		win
																				.getComponent(
																						0)
																				.getForm()
																				.submit(
																						{
																							url : 'updateemployees.do',
																							success : function() {
																								alert("添加成功！");
																								win
																										.hide();
																								vstore
																										.reload();
																							}
																						});

																	}
																},
																{
																	text : "重置",
																	handler : function() {
																		var record = grid
																				.getSelectionModel()
																				.getSelected();
																		win
																				.getComponent(
																						0)
																				.getForm()
																				.loadRecord(
																						record);
																	}
																} ],
														items : [

																{
																	xtype : "textfield",
																	fieldLabel : "员工编号",
																	name : "code",
																	minValue : "pcode" + 1,
																	vtypeText : "员工编号必须大于上级员工编号",
																	readOnly : true
																// disabled:true
																},
																{
																	xtype : "textfield",
																	fieldLabel : "员工姓名",
																	name : "name"
																},
																{
																	xtype : "datefield",
																	fieldLabel : "生日",
																	name : "birthday",
																	format : 'Y-m-d'
																},
																{
																	xtype : "textfield",
																	fieldLabel : "区域",
																	name : "area"
																},
																{
																	xtype : "textfield",
																	fieldLabel : "证件号码",
																	name : "idcard"
																},
																{
																	xtype : "textfield",
																	fieldLabel : "上级员工编号",
																	name : "pcode",
																	id : "pcode",
																	readOnly : true
																// disabled :
																// true

																} ]
													}
												});
										win.show();
										var record = grid.getSelectionModel()
												.getSelected();
										win.getComponent(0).getForm()
												.loadRecord(record);
									}
								},
								'->',
								{
									text : "删除",
									handler : function() {
										var record = grid.getSelectionModel()
												.getSelected();
										var code = record.get("code");
										Ext.Ajax.request({
											url : "deleteemployees.do",
											params : {
												code : code
											}
										});
										vstore.reload();
									}
								} ],
						columns : [ {
							header : "员工编号",
							dataIndex : "code",
							editor : new Ext.form.TextField()
						}, {
							header : "员工姓名",
							dataIndex : "name",
							editor : new Ext.form.TextField()
						}, {
							header : "生日",
							dataIndex : "birthday",
							editor : new Ext.form.TextField()
						}, {
							header : "上级员工姓名",
							dataIndex : "pname",
							editor : new Ext.form.TextField()
						}, {
							header : "区域",
							dataIndex : "area",
							editor : new Ext.form.TextField()
						}, {
							header : "证件号码",
							dataIndex : "idcard",
							sortable : true,
							editor : new Ext.form.TextField(),
							width : 140
						}, {
							header : "上级员工编号",
							dataIndex : "pcode",
							sortable : true,
							editor : new Ext.form.TextField(),
							width : 130
						} ]
					});

			var viewport = new Ext.Viewport(
					{
						layout : "border",
						items : [
								{
									region : "north",
									height : 30,
									html : '<h1 align="center"><a href="getstructure.do">员工结构图</a></h1>'
								},
								{
									region : 'west',
									collapsible : true,
									title : '员工树',
									xtype : 'treepanel',
									root : {
										nodeType : 'async',
										text : '全部',
										draggable : false,
										id : 'source'
									},
									width : 200,
									autoScroll : true,
									split : true,
									loader : new Ext.tree.TreeLoader({
										dataUrl : 'gettree.do'
									}),
									root : new Ext.tree.AsyncTreeNode(
											{
												expanded : true,
												listeners : {
													click : function(n) {
														Ext.Msg
																.alert(
																		'Navigation Tree Click',
																		'You clicked: "'
																				+ n.attributes.text
																				+ '"');
													}
												}
											})
								}, {
									title : "面板3",
									// width : 100,
									region : "center",
									xtype : "panel",
									items : grid,
									layout : 'fit'

								} ]
					});
		});